<html>
<head><meta charset="utf-8"><title>Method for promotion in `const` · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Method.20for.20promotion.20in.20.60const.60.html">Method for promotion in `const`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="178907541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Method%20for%20promotion%20in%20%60const%60/near/178907541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Method.20for.20promotion.20in.20.60const.60.html#178907541">(Oct 23 2019 at 23:41)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> , you've mentioned that you'd like to create actual MIR <code>promoted</code>s within <code>const</code>s, instead of just removing <code>Drop</code> and <code>StorageDead</code> for things that need lifetime extension.</p>



<a name="178907634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Method%20for%20promotion%20in%20%60const%60/near/178907634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Method.20for.20promotion.20in.20.60const.60.html#178907634">(Oct 23 2019 at 23:42)</a>:</h4>
<p>I had a fix in mind for <a href="https://github.com/rust-lang/rust/issues/65732" target="_blank" title="https://github.com/rust-lang/rust/issues/65732">#65732</a> that would preserve the existing way of doing promotion, but requires changing the output of various MIR queries.</p>



<a name="178907653"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Method%20for%20promotion%20in%20%60const%60/near/178907653" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Method.20for.20promotion.20in.20.60const.60.html#178907653">(Oct 23 2019 at 23:43)</a>:</h4>
<p>It's pointless to do this if we are planning to do the same thing everywhere</p>



<a name="178907756"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Method%20for%20promotion%20in%20%60const%60/near/178907756" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Method.20for.20promotion.20in.20.60const.60.html#178907756">(Oct 23 2019 at 23:45)</a>:</h4>
<p>So what are the upsides of the current approach? Do you think it was just a premature optimization? Should I start working to make it go away? I've previously mentioned to <span class="user-mention" data-user-id="119009">@eddyb</span> that this gets a bit easier once <a href="https://github.com/rust-lang/rust/issues/63812" target="_blank" title="https://github.com/rust-lang/rust/issues/63812">#63812</a> is merged</p>



<a name="178907821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Method%20for%20promotion%20in%20%60const%60/near/178907821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Method.20for.20promotion.20in.20.60const.60.html#178907821">(Oct 23 2019 at 23:46)</a>:</h4>
<p>It does seem a little silly to pull stuff out of one const <code>Body</code> and put it into another I guess.</p>



<a name="178908042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Method%20for%20promotion%20in%20%60const%60/near/178908042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Method.20for.20promotion.20in.20.60const.60.html#178908042">(Oct 23 2019 at 23:50)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> was confused by it and I'd rather get rid of it than try to document the confusing promotion triangle</p>



<a name="178908167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Method%20for%20promotion%20in%20%60const%60/near/178908167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Method.20for.20promotion.20in.20.60const.60.html#178908167">(Oct 23 2019 at 23:53)</a>:</h4>
<p>(<code>let</code>-like scope extension, promotion via scope extension, proper promotion)</p>



<a name="178908244"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Method%20for%20promotion%20in%20%60const%60/near/178908244" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Method.20for.20promotion.20in.20.60const.60.html#178908244">(Oct 23 2019 at 23:55)</a>:</h4>
<p>Okay, but no pressing concerns? The split has caused bugs already, so I have no problem trying to do the same thing everywhere.</p>



<a name="178908276"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Method%20for%20promotion%20in%20%60const%60/near/178908276" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Method.20for.20promotion.20in.20.60const.60.html#178908276">(Oct 23 2019 at 23:56)</a>:</h4>
<p>I should be able to make <code>qualify_consts</code> more understandable once I remove the old promoter/checker/qualifier.</p>



<a name="178908359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Method%20for%20promotion%20in%20%60const%60/near/178908359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Method.20for.20promotion.20in.20.60const.60.html#178908359">(Oct 23 2019 at 23:57)</a>:</h4>
<p>Perhaps that could help avoid bugs in the future.</p>



<a name="178908375"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Method%20for%20promotion%20in%20%60const%60/near/178908375" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Method.20for.20promotion.20in.20.60const.60.html#178908375">(Oct 23 2019 at 23:57)</a>:</h4>
<p>(if we were to continue using separate approaches)</p>



<a name="178909058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Method%20for%20promotion%20in%20%60const%60/near/178909058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Method.20for.20promotion.20in.20.60const.60.html#178909058">(Oct 24 2019 at 00:09)</a>:</h4>
<p>first two rely on missing StorageDead, last two involve mutating MIR in promote_consts</p>



<a name="178928005"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Method%20for%20promotion%20in%20%60const%60/near/178928005" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Method.20for.20promotion.20in.20.60const.60.html#178928005">(Oct 24 2019 at 07:39)</a>:</h4>
<p>@eddyb I was confused mostly because I didn't expect it.^^ With proper docs I do<br>
not see anything fundamentally wrong with the current approach. (I haven't had<br>
the time to read ecstatic's new docs yet.) That said, if you think this should<br>
be refactored anyway and all you need is an excuse, I am fine with being that<br>
excuse. ;)</p>
<p>(Just a quick reply via email; I'm too busy for Zulip for another week I'm afraid.)</p>



<a name="179193044"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Method%20for%20promotion%20in%20%60const%60/near/179193044" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Method.20for.20promotion.20in.20.60const.60.html#179193044">(Oct 28 2019 at 00:08)</a>:</h4>
<p>One limitation is that it doesn't extend to loops, e.g. <code>loop { x = &amp;0 }</code> will fail.</p>



<a name="179196524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Method%20for%20promotion%20in%20%60const%60/near/179196524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Method.20for.20promotion.20in.20.60const.60.html#179196524">(Oct 28 2019 at 01:53)</a>:</h4>
<p>Found this by accident while working on <a href="https://github.com/rust-lang/rust/issues/65883" target="_blank" title="https://github.com/rust-lang/rust/issues/65883">#65883</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>